// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

int t, k;
int p;

const int N = 55, M = 105;

int dp[N][N * M];

int sum[N][M];

int n;

int main(int argc, char const *argv[]) {
    // code
    int t;
    scanf("%d", &t);
    for (int kk=0; kk<t; ++kk) {
        scanf("%d%d%d", &n, &k, &p);
        for (int i=0; i<=n; ++i) {
            memset(dp[i], 0, sizeof dp[i]);
            memset(sum[i], 0, sizeof sum[i]);
        }

        for (int i=1; i<=n; ++i) {
            sum[i][0] = 0;
            for (int j=1; j<=k; ++j)
                scanf("%d", &sum[i][j]);
            for (int j=1; j<=k; ++j)
                sum[i][j] += sum[i][j-1];
        }

        for (int i=1; i<=n; ++i) {
            for (int j=1; j<=p; ++j) {
                for (int q=0; q<=min(k, j); ++q)
                    dp[i][j] = max(dp[i][j], dp[i-1][j-q] + sum[i][q]);
            }
        }

        printf("Case #%d: %d\n", kk+1, dp[n][p]);
    }
    return 0;
}
